﻿using UnityEngine;

namespace TC
{
    /// <summary>
    /// 绑定Event
    /// </summary>
    public class BindEventNode : EventNode
    {
        public EventEntity entity;

        /// <summary>
        /// 暂存当前接受到的参数值列表
        /// </summary>
        public Context e;

        public BindEventNode(EventEntity entity)
        {
            this.entity = entity;
        }

        public override void OnCreate()
        {
            base.OnCreate();

            foreach (var i in entity.paramsDic)
            {
                if (i.Value is ByteVar)
                {
                    this.AddValueOutPort<byte>(i.Key, () => { return e.Get<byte>(i.Key); });
                }
                else if (i.Value is ShortVar)
                {
                    this.AddValueOutPort<short>(i.Key, () => { return e.Get<short>(i.Key); });
                }
                else if (i.Value is IntVar)
                {
                    this.AddValueOutPort<int>(i.Key, () => { return e.Get<int>(i.Key); });
                }
                else if (i.Value is LongVar)
                {
                    this.AddValueOutPort<long>(i.Key, () => { return e.Get<long>(i.Key); });
                }
                else if (i.Value is FloatVar)
                {
                    this.AddValueOutPort<float>(i.Key, () => { return e.Get<float>(i.Key); });
                }
                else if (i.Value is DoubleVar)
                {
                    this.AddValueOutPort<double>(i.Key, () => { return e.Get<double>(i.Key); });
                }
                else if (i.Value is CharVar)
                {
                    this.AddValueOutPort<char>(i.Key, () => { return e.Get<char>(i.Key); });
                }
                else if (i.Value is VectorVar)
                {
                    this.AddValueOutPort<Vector4>(i.Key, () => { return e.Get<Vector3>(i.Key); });
                }
                else if (i.Value is ObjectVar)
                {
                    this.AddValueOutPort<object>(i.Key, () => { return e.Get<object>(i.Key); });
                }
            }
        }

        #region flow
        public void Execute(Context e)
        {
            this.e = e;//把事件参数保存下来

            //this.Send();//再去call
            //this.flowOut.Call();
        }
        #endregion

        #region value
        #endregion
    }
}
